package com.zhuss.food.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.food.product.CreateProductBo;
import com.zhuss.bean.bo.food.product.DeleteProductBo;
import com.zhuss.bean.bo.food.product.DownProductBo;
import com.zhuss.bean.bo.food.product.UpdateProductBo;
import com.zhuss.bean.bo.food.product.UpperProductBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.WpsException;

/**
 * 商品操作service（基本操作）
 * @author zhushanshuo
 * @Date 2020/02/28 16:01
 *
 */
@Component("productOperateService")
public class ProductOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("productCreate")
	private Processor<Object, CreateProductBo> productCreate;
	
	@Autowired
	@Qualifier("productUpdate")
	private Processor<Object, UpdateProductBo> productUpdate;
	
	@Autowired
	@Qualifier("productUpper")
	private Processor<Object, UpperProductBo> productUpper;
	
	@Autowired
	@Qualifier("productDown")
	private Processor<Object, DownProductBo> productDown;
	
	@Autowired
	@Qualifier("productDelete")
	private Processor<Object, DeleteProductBo> productDelete;
	
	/**
	 * 创建
	 */
	@Override
	public Void create(Object param) throws WpsException {
		
		CreateProductBo bo = (CreateProductBo) param;
		
		productCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws WpsException {
    	
		UpdateProductBo bo = (UpdateProductBo) param;
		
		productUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws WpsException {
		
		DeleteProductBo bo = (DeleteProductBo) param;
		
		productDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 上架商品
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void upper(Object param) throws WpsException {
		
		UpperProductBo bo = (UpperProductBo) param;
		
		productUpper.process(bo);
		
		return null;
	}
	
	/**
	 * 下架商品
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void down(Object param) throws WpsException {
		
		DownProductBo bo = (DownProductBo) param;
		
		productDown.process(bo);
		
		return null;
	}
	
}

